<template>
  <view>
    <view class="add-title t-a-c">
      <text class="f-s-18 f-w m-r-10">{{title}}</text>
      <text class="iconfont icon-shezhi f-w"></text>
    </view>
    <view class="add-input m-t-20">
      <textarea :value="inputVal" class="p-all-10 f-s-14" placeholder="说一句话吧~" style="width: 100%;"></textarea>
    </view>
    <view class="add-select p-all-20">
      <button class="l-h-80 t-a-c f-s-16" size="mini" plain="true" type="warn"><text
          class="iconfont icon-caidan m-r-10"></text>请选择分类</button>
      <br>
      <button class="l-h-80 t-a-c f-s-16 m-t-10" size="mini" plain="true" type="warn"><text
          class="iconfont icon-huati m-r-10"></text>请选择话题</button>
    </view>
    <view class="add-img p-all-20">
      <my-uploadImage :list="imageList" @chooseImg="chooseImg"></my-uploadImage>
    </view>
    <view style="height: 100rpx;"></view>
    <view class="add-buttom flex-b p-all-20" style="position: fixed;left: 0;bottom: 0;width: 95%;">
      <view>
        <text class="iconfont icon-caidan f-w m-r-20" style="font-size: 30px;"></text>
        <text class="iconfont icon-huati fw m-r-20" style="font-size: 30px;"></text>
        <text class="iconfont icon-tupian fw m-r-20" style="font-size: 30px;"></text>
      </view>
      <view class=" main-bg-color font-color-white t-a-c l-h-70 b-r-10" style="width: 150rpx;height: 70rpx;">发送
      </view>
    </view>
  </view>
</template>

<script>
  export default {
    data() {
      return {
        title: '所有人可见',
        imageValue: [],
        imageList: [],
        inputVal: '',
        back: true
      };
    },
    methods: {
      chooseImg(data) {
        this.imageList = data
      },
      saveDraft() {
        uni.setStorageSync("add-input", JSON.stringify({
          'inputVal': this.inputVal,
          'imageList': this.imageList
        }))
      }
    },
    onLoad() {
      this.back = true
      const data = uni.getStorageSync("add-input")
      if (data) {
        this.inputVal = data.inputVal
        this.imageList = data.imageList
        uni.removeStorageSync("add-input")
      }
    },
    onBackPress() {
      if ((this.inputVal !== '' || this.imageValue.length !== 0) && this.back) {
        this.back = false
        uni.showModal({
          title: '保存草稿',
          content: '是否要保存为草稿？',
          confirmText: '保存',
          cancelText: '不保存',
          showCancel: true,
          success: res => {
            if (res.confirm) {
              this.saveDraft()
              uni.switchTab({
                url: '/pages/home/home'
              })
            } else {
              return false
            }
            return true
          }
        })
      } else {
        return false
      }
    }
  }
</script>

<style lang="scss">

</style>